-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PLUGIN-1826] Error Management HTTP Source and Sink and fix sonar issues #180
base: develop
Are you sure you want to change the base?
[PLUGIN-1826] Error Management HTTP Source and Sink and fix sonar issues #180
Conversation
Amit-CloudSufi
commented
Dec 6, 2024
•
edited
Loading
edited
- Jira : https://cdap.atlassian.net/browse/PLUGIN-1826
This comment was marked as resolved.
This comment was marked as resolved.
4cad117
to
fac0c1a
Compare
e612cd0
to
d273336
Compare
0af6ccc
to
a41b2f6
Compare
…ckage to handle error provider, fix sonar issues and added Validation error for linear retry duration
4f1d5f5
to
2e321fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please fix unit tests
errorMessage, String.format("Error message: %s", errorMessage), | ||
ErrorUtils.getActionErrorByStatusCode(httpStatusCode).getErrorType(), | ||
true, ErrorCodeType.HTTP, String.valueOf(httpStatusCode), | ||
"https://developer.mozilla.org/en-US/docs/Web/HTTP/Status", new IllegalStateException(errorMessage)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should use official documentations link: https://datatracker.ietf.org/doc/html/rfc7231#section-6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
String errorMessage = String.format("Fetching from url '%s' returned status code '%d' and body '%s'", | ||
nextPageUrl, httpStatusCode, response.getBody()); | ||
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), | ||
errorMessage, String.format("Error message: %s", errorMessage), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't do redundant Error message: %s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed from all files
@@ -122,8 +130,13 @@ protected BasePage getNextPage() throws IOException { | |||
case SUCCESS: | |||
break; | |||
case STOP: | |||
throw new IllegalStateException(String.format("Fetching from url '%s' returned status code '%d' and body '%s'", | |||
nextPageUrl, httpStatusCode, response.getBody())); | |||
String errorMessage = String.format("Fetching from url '%s' returned status code '%d' and body '%s'", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errorReason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
throw new IllegalArgumentException("Invalid URL: " + configURL, e); | ||
} catch (IOException e) { | ||
LOG.warn("Error making {} request to URL {}.", config.getMethod(), config.getUrl()); | ||
String errorMessage = "Unable to make request. "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not an actional error reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
LOG.warn("Error making {} request to URL {}.", config.getMethod(), config.getUrl()); | ||
String errorMessage = "Unable to make request. "; | ||
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), | ||
errorMessage, String.format("Error message: %s", errorMessage), ErrorType.UNKNOWN, true, e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar comment here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
if (!shouldRetry) { | ||
messageBuffer.clear(); | ||
retryCount = 0; | ||
String errorMessage = String.format("Unable to execute HTTP request to %s.", url); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
errorReason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
retryCount = 0; | ||
String errorMessage = String.format("Unable to execute HTTP request to %s.", url); | ||
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), | ||
errorMessage, String.format("Error message: %s", errorMessage), ErrorType.SYSTEM, true, e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar comment here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
String errorMessage = String.format("Unable to execute HTTP request to %s.", url); | ||
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), | ||
errorMessage, String.format("Error message: %s", errorMessage), ErrorType.SYSTEM, true, e); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove empty line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
} catch (Exception e) { | ||
String errorMessage = String.format("Unexpected error occurred while executing HTTP request to URL: %s", url); | ||
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), | ||
errorMessage, String.format("Error message: %s", errorMessage), ErrorType.UNKNOWN, true, e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar comment here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
@@ -247,16 +263,16 @@ public CloseableHttpClient createHttpClient(String pageUriStr) throws IOExceptio | |||
URI uri = URI.create(pageUriStr); | |||
AuthScope authScope = new AuthScope(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme())); | |||
credentialsProvider.setCredentials(authScope, | |||
new UsernamePasswordCredentials(config.getUsername(), config.getPassword())); | |||
new UsernamePasswordCredentials(config.getUsername(), config.getPassword())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert unintended changes.
new UsernamePasswordCredentials( | ||
config.getProxyUsername(), config.getProxyPassword())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert unintended changes
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove empty line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
@@ -311,7 +324,7 @@ private Header getAuthorizationHeader(AccessToken accessToken) { | |||
private List<PlaceholderBean> getPlaceholderListFromURL() { | |||
List<PlaceholderBean> placeholderList = new ArrayList<>(); | |||
if (!(config.getMethod().equals(REQUEST_METHOD_PUT) || config.getMethod().equals(REQUEST_METHOD_PATCH) || | |||
config.getMethod().equals(REQUEST_METHOD_DELETE))) { | |||
config.getMethod().equals(REQUEST_METHOD_DELETE))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert unintended changes
.await().with() | ||
.pollInterval(pollInterval) | ||
.pollDelay(config.getWaitTimeBetweenPages(), TimeUnit.MILLISECONDS) | ||
.timeout(config.getMaxRetryDuration(), TimeUnit.SECONDS) | ||
.until(this::executeHTTPServiceAndCheckStatusCode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert unintended changes
String errorMessage = "Error while executing http request for remaining input messages" + | ||
" after the batch execution."; | ||
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), | ||
errorMessage, String.format("Error message: %s", errorMessage), ErrorType.UNKNOWN, true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar comment here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also don't we have status code information here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
} catch (Exception e) { | ||
throw new RuntimeException("Error while executing http request for remaining input messages " + | ||
"after the batch execution. " + e); | ||
String errorMessage = "Error while executing http request for remaining input messages" + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add http request information here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
errorMessage, String.format("Error message: %s", errorMessage), | ||
ErrorUtils.getActionErrorByStatusCode(httpStatusCode).getErrorType(), | ||
true, ErrorCodeType.HTTP, String.valueOf(httpStatusCode), | ||
"https://developer.mozilla.org/en-US/docs/Web/HTTP/Status", new IllegalStateException(errorMessage)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar comment here about documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
String errorMessage = String.format("Fetching from url '%s' returned status code '%d' and body '%s'", | ||
config.getUrl(), httpStatusCode, httpResponseBody); | ||
throw ErrorUtils.getProgramFailureException(new ErrorCategory(ErrorCategory.ErrorCategoryEnum.PLUGIN), | ||
errorMessage, String.format("Error message: %s", errorMessage), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar comment here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
case SKIP: | ||
case SEND: | ||
LOG.warn(String.format("Fetching from url '%s' returned status code '%d' and body '%s'", | ||
config.getUrl(), httpStatusCode, httpResponseBody)); | ||
config.getUrl(), httpStatusCode, httpResponseBody)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert unintended changes
@@ -1,3 +1,4 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove empty line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed